<style type="text/css">
	#tpl-file-info-id{
		padding: 20px
	}

	#tpl-file-info-id .icon{height: 38px;line-height: 38px;text-align: center;}
	#tpl-file-info-id .icon i{font-size: 2rem;font-weight: 800;color: blue;margin-left: 1rem;margin-right: 1rem;cursor: pointer;color: #717171}
	.tpl-file-info-id-collect{
		color: #ffb800 !important;
	}
</style>
<script type="text/html" id="tpl-file_history">
	<table class="layui-hide" id="file_history" lay-filter="file_history"></table>
</script>
<script type="text/html" id="bar_file_history">
  <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">使用</a> -->
  <a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
  <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>
<!-- 文件尺寸模板 -->
<script type="text/html" id="tpl_file_history_size">
	{{# if(d.size==0){ }}
		0 B
	{{# }else if(d.size){ }}
		{{app.bytesToSize(d.size)}}
	{{# }else{ }}
		-
	{{# } }}
</script>
<script type="text/javascript">
	app.defTpl('file_history',function(arg){
		layui.use(['layer','laytpl','table'],function(){
			var laytpl = layui.laytpl,$=layui.$;
			var table = layui.table;
			app.ajaxPost('/api/file/getFileHistoryVersion',{fileId:arg.file_id},function(data){
				var d=data.data;
				console.log(data);
				laytpl($('#tpl-file_history').html()).render(d, function (html) {
					app.layer({
						type: 1,
						title: '文件历史',
						anim: 2,
						// area: ['400px'],
						shade: 0.5,
						shadeClose: true,
						content: html,
						success: function (o, index) {
							console.log('渲染');
							table.render({
								elem: '#file_history'
								// , url: '/test/table/demo1.json'
								, data:d
								, size: 'sm'
								, cols: [[
									 { field: 'file_name', title: '文件名'}
									 
									// , { field: 'path', title: '路径' }
									 ,{ field: 'last_update_time', title: '更新时间', width: 150 }
									, { field: 'size', title: '尺寸', sort: true ,toolbar:'#tpl_file_history_size'}
									, { fixed: 'right', title: '操作', toolbar: '#bar_file_history', width: 80 }
								]]
							});

							//监听行工具事件
							table.on('tool(file_history)', function (obj) {
								var data = obj.data;
								console.log(obj)
								if (obj.event === 'del') {
									// layer.confirm('真的删除行么', function (index) {
									// 	obj.del();
									// 	layer.close(index);
									// });
								} else if (obj.event === 'download') {
									window.open('/source/downloadByHistoryId?historyId='+ data.id)
								}
							});
						}
					})
				})
			})
		})
	});
</script>